<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Suggest_m extends CI_Model {

	const TBL = 'suggestion';

	/**
     * 构造函数
     *
     * @access public
     * @return void
     */
    public function __construct()
    {
       parent::__construct();
    }

	function get_suggestion_by_id($id){
		$this->db->where('id', $id);
		$query = $this->db->get(self::TBL);
		return $query->row_array();
	}
	
	function get_count(){
		$this->db->from(self::TBL);
		return $this->db->count_all_results();
	}
	
	function add_suggest($name, $contact, $content=''){

		$this->db->set('name', $name);
		$this->db->set('contact', $contact);
		$this->db->set('content', $content);
		if($this->db->insert(self::TBL)){
			return $this->db->insert_id();
		}

		return false;
	}
	
	function reply_suggest($id, $reply){
		$this->db->where('id', $id);
		$data = array(
					'reply' => $reply,
					'replytime' => date("Y-m-d H:i:s")
					);
		$this->db->update(self::TBL, $data);
	}

	function get_paged_suggestion($offset = 0, $row_count = 0){
		$this->db->order_by('id desc');
		$query = $this->db->get(self::TBL, $row_count, $offset);
		return $query->result_array();
	}


}

/* End of file users_mdl.php */
/* Location: ./application/models/users_mdl.php */
